<?
session_start();
include('../config.php');
require_once('../classes/class.jira.php');
include("../classes/connect.php");
ini_set('display_errors', 'On');

?>

<!DOCTYPE html>
<html>
<head>
    <title>Date axis</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" >

    <link href="examples/content/shared/styles/examples-offline.css" rel="stylesheet">
    <link href="styles/kendo.dataviz.min.css" rel="stylesheet">
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
    <link href="../css/header.css" rel="stylesheet">

    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.dataviz.min.js"></script>
    <script src="examples/content/shared/js/console.js"></script>
    <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
  
    <a class="offline-button" href="../home.php">Back</a>
    <div id="example" class="k-content">
          

        
            <div style="float:left"> 
        <div class="configuration k-widget k-header" style="width:170px; z-index: 9999;">
                <span class="configHead">Base date unit</span>
                <ul class="options">
<!--                    <li>
                        <input id="baseUnitAuto" name="baseUnit"
                                type="radio" value="" autocomplete="off" onclick="subscribe()"/>
                        <label for="baseUnitAuto">Automatic (default)</label>
                    </li>-->
                    <li>
                        <input id="baseUnitYears" name="baseUnit"
                                type="radio" value="years" autocomplete="off" onclick="subscribe()" />
                        <label for="baseUnitYears">Year</label>
                    </li>
                    <li>
                        <input id="baseUnitMonths" name="baseUnit"
                                type="radio" value="months"  autocomplete="off" onclick="subscribe()" />
                        <label for="baseUnitMonths">Month</label>
                    </li>
                    <li>
                        <input id="baseUnitWeeks" name="baseUnit"
                                type="radio" value="weeks" checked="checked" autocomplete="off" onclick="subscribe()" />
                        <label for="baseUnitWeeks">Week</label>
                    </li>
                    <span class="configHead"></span>
                   <span class="configHead"><a href="delayreport.php">Delay Report</a></span>
                </ul>
            </div>
                <div style="margin:18px;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.45), 0 0 30px rgba(0, 0, 0, 0.07) inset; padding: 21px;border-radius: 8px">
                    <div class="span13">
                        <p><label>From:</label> <input type="text" id="fromdatepicker"/></p>
                    </div>
                    <div class="reptodate">
                            <p><label>To: </label><input type="text" id="todatepicker"/></p>
                    </div>
                    <div class="repsubmit">
                            <input type="button" value="submit" onclick="datecheck();"/>
                    </div>
                </div>
                
                 
            </div>
          
            <div class="chart-wrapper">
                <div id="chart"></div>
            </div>
			
<script>
    
     $(document).ready(function() {
         
         var fromdatestr="<?php echo  date('Y/m/d',strtotime('last monday'));?> ";
      //   alert(fromdatestr);
         var todatestr="<?php echo  date('Y/m/d',strtotime('next friday'));?> ";
            $.ajax({
		  url: 'ajaxChartWeek.php?fromdate='+fromdatestr+'&todate='+todatestr,
		  dataType:'json',
                  success: function(data)          //on recieve of reply
                    {
                            var n=data.split("-");
                            var from=n[0];
                            var to=n[1];
                            var total=n[2];
                            var opencv=Math.round((n[3]/n[2])*100);
                            var rejected=Math.round((n[4]/n[2])*100);
                            var shortlist=Math.round((n[5]/n[2])*100);
                            
                            var Interviewed=Math.round((n[6]/n[2])*100);
                            var Tested=Math.round((n[7]/n[2])*100);
                            var Selected=Math.round((n[8]/n[2])*100);
                            var Offered=Math.round((n[9]/n[2])*100);
                            var InterviewCalled=Math.round((n[10]/n[2])*100);
                            var TestCalled=Math.round((n[11]/n[2])*100);
                            var FinalInterviewCalled=Math.round((n[12]/n[2])*100);
                            var FinalInterviewed=Math.round((n[13]/n[2])*100);
                            var Joined=Math.round((n[14]/n[2])*100);
                            
                        //    alert(n[5]);
//                            console.log(opencv+' '+rejected+' '+shortlist);
//                            var OpenCV=parseFloat(Math.round(opencv * 100) / 100).toFixed(2);
//                            var Rejected=parseFloat(Math.round(rejected * 100) / 100).toFixed(2);
//                            var Shortlist=parseFloat(Math.round(shortlist * 100) / 100).toFixed(2);
                           //alert(parseFloat(Math.round(opencv * 100) / 100).toFixed(2));
                           createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
                                       n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14] );
                    }
		});
        });
  
//    $( "#baseUnit" ).click(function(){
//        
//            alert('d');
//        });
//  
$(document).ready(function(){
function subscribe() {
     $('input[type="radio"]').click(function(){
        
        var auto = document.getElementById("baseUnitAuto");
        var year = document.getElementById("baseUnitYears");
        var month = document.getElementById("baseUnitMonths");
        var week = document.getElementById("baseUnitWeeks");
        var day = document.getElementById("baseUnitDays");
//        if(auto.checked === true){
//          alert('dfdfdf');
//        }
//        else 
            if(year.checked === true) {
           var fromdatestr="<?php echo  date('Y/m/d',strtotime('first day of January '.date('Y')));?> ";
        // alert(fromdatestr);
         var todatestr="<?php echo  date('Y/m/d',strtotime('next friday'));?> ";
            $.ajax({
		  url: 'ajaxChartWeek.php?year='+fromdatestr+'&todate='+todatestr,
		  dataType:'json',
                  success: function(data)          //on recieve of reply
                    {
                            var n=data.split("-");
                            var from=n[0];
                            var to=n[1];
                            var total=n[2];
                            var opencv=Math.round((n[3]/n[2])*100);
                            var rejected=Math.round((n[4]/n[2])*100);
                            var shortlist=Math.round((n[5]/n[2])*100);
                            
                            var Interviewed=Math.round((n[6]/n[2])*100);
                            var Tested=Math.round((n[7]/n[2])*100);
                            var Selected=Math.round((n[8]/n[2])*100);
                            var Offered=Math.round((n[9]/n[2])*100);
                            var InterviewCalled=Math.round((n[10]/n[2])*100);
                            var TestCalled=Math.round((n[11]/n[2])*100);
                            var FinalInterviewCalled=Math.round((n[12]/n[2])*100);
                            var FinalInterviewed=Math.round((n[13]/n[2])*100);
                            var Joined=Math.round((n[14]/n[2])*100);
                            
                        //    alert(n[5]);
//                            console.log(opencv+' '+rejected+' '+shortlist);
//                            var OpenCV=parseFloat(Math.round(opencv * 100) / 100).toFixed(2);
//                            var Rejected=parseFloat(Math.round(rejected * 100) / 100).toFixed(2);
//                            var Shortlist=parseFloat(Math.round(shortlist * 100) / 100).toFixed(2);
                           //alert(parseFloat(Math.round(opencv * 100) / 100).toFixed(2));
                           createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
                                       n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14] );
                    }
		});
        }
        else if(month.checked === true) {
           var fromdatestr="<?php echo  date('Y/m/d',strtotime('first day of '.date('F-Y') ));?> ";
        // alert(fromdatestr);
         var todatestr="<?php echo  date('Y/m/d',strtotime('next friday'));?> ";
            $.ajax({
		  url: 'ajaxChartWeek.php?fromdate='+fromdatestr+'&todate='+todatestr,
		  dataType:'json',
                  success: function(data)          //on recieve of reply
                    {
                            var n=data.split("-");
                            var from=n[0];
                            var to=n[1];
                            var total=n[2];
                            var opencv=Math.round((n[3]/n[2])*100);
                            var rejected=Math.round((n[4]/n[2])*100);
                            var shortlist=Math.round((n[5]/n[2])*100);
                            
                            var Interviewed=Math.round((n[6]/n[2])*100);
                            var Tested=Math.round((n[7]/n[2])*100);
                            var Selected=Math.round((n[8]/n[2])*100);
                            var Offered=Math.round((n[9]/n[2])*100);
                            var InterviewCalled=Math.round((n[10]/n[2])*100);
                            var TestCalled=Math.round((n[11]/n[2])*100);
                            var FinalInterviewCalled=Math.round((n[12]/n[2])*100);
                            var FinalInterviewed=Math.round((n[13]/n[2])*100);
                            var Joined=Math.round((n[14]/n[2])*100);
                            
                       
                           createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
                                       n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14] );
                    }
		});
        }
        else if(week.checked === true) {
           var fromdatestr="<?php echo  date('Y/m/d',strtotime('last monday '));?> ";
        // alert(fromdatestr);
         var todatestr="<?php echo  date('Y/m/d',strtotime('next friday'));?> ";
            $.ajax({
		  url: 'ajaxChartWeek.php?fromdate='+fromdatestr+'&todate='+todatestr,
		  dataType:'json',
                  success: function(data)          //on recieve of reply
                    {
                            var n=data.split("-");
                            var from=n[0];
                            var to=n[1];
                            var total=n[2];
                            var opencv=Math.round((n[3]/n[2])*100);
                            var rejected=Math.round((n[4]/n[2])*100);
                            var shortlist=Math.round((n[5]/n[2])*100);
                            
                            var Interviewed=Math.round((n[6]/n[2])*100);
                            var Tested=Math.round((n[7]/n[2])*100);
                            var Selected=Math.round((n[8]/n[2])*100);
                            var Offered=Math.round((n[9]/n[2])*100);
                            var InterviewCalled=Math.round((n[10]/n[2])*100);
                            var TestCalled=Math.round((n[11]/n[2])*100);
                            var FinalInterviewCalled=Math.round((n[12]/n[2])*100);
                            var FinalInterviewed=Math.round((n[13]/n[2])*100);
                            var Joined=Math.round((n[14]/n[2])*100);
                            
                       
                           createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
                                       n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14] );
                    }
		});
        }
       
    });
}
subscribe();
});


 $(function() {
	$( "#fromdatepicker" ).datepicker({ maxDate: "-1d" });
	$( "#todatepicker" ).datepicker({ maxDate: "0d" });
	});
        
	function datecheck(){
		var fromdate=$( "#fromdatepicker" ).datepicker( "getDate" );;
		var todate=$( "#todatepicker" ).datepicker( "getDate" );
		
		var fromdatestr=$.datepicker.formatDate('yy/mm/dd', fromdate);
		var todatestr=$.datepicker.formatDate('yy/mm/dd', todate);
				
		if(fromdate==null || todate==null){
			alert('Please Enter a valid date');
		}
		var dates= new Array();
		while(fromdate<=todate){
			var current=$.datepicker.formatDate('yy/mm/dd', fromdate);
			// alert(current);
			dates.push(new Date(current));						
			fromdate.setDate(fromdate.getDate()+1);					
		}
		$.ajax({
		  url: 'ajaxChartWeek.php?fromdate='+fromdatestr+'&todate='+todatestr,
		  dataType:'json',
                  success: function(data)          //on recieve of reply
                    {
                            var n=data.split("-");
                            var from=n[0];
                            var to=n[1];
                            var total=n[2];
                            var opencv=Math.round((n[3]/n[2])*100);
                            var rejected=Math.round((n[4]/n[2])*100);
                            var shortlist=Math.round((n[5]/n[2])*100);
                            
                            var Interviewed=Math.round((n[6]/n[2])*100);
                            var Tested=Math.round((n[7]/n[2])*100);
                            var Selected=Math.round((n[8]/n[2])*100);
                            var Offered=Math.round((n[9]/n[2])*100);
                            var InterviewCalled=Math.round((n[10]/n[2])*100);
                            var TestCalled=Math.round((n[11]/n[2])*100);
                            var FinalInterviewCalled=Math.round((n[12]/n[2])*100);
                            var FinalInterviewed=Math.round((n[13]/n[2])*100);
                            var Joined=Math.round((n[14]/n[2])*100);
                            
                        //    alert(n[5]);
//                            console.log(opencv+' '+rejected+' '+shortlist);
//                            var OpenCV=parseFloat(Math.round(opencv * 100) / 100).toFixed(2);
//                            var Rejected=parseFloat(Math.round(rejected * 100) / 100).toFixed(2);
//                            var Shortlist=parseFloat(Math.round(shortlist * 100) / 100).toFixed(2);
                           //alert(parseFloat(Math.round(opencv * 100) / 100).toFixed(2));
                           createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
                                       n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14] );
                    }
		});
                        
              
	}	
           function onSeriesClick(e) {
                alert("Clicked value: " + e.value);
            }
	//function createChart(dates,OpenCV,ShortListed,Interviewed,Tested,Selected,Rejected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined) {
	function createChart(from,to,opencv,rejected,shortlist,Interviewed,Tested,Selected,Offered,InterviewCalled,TestCalled,FinalInterviewCalled,FinalInterviewed,Joined,total,
            toopencv,torejected,toshortlist,toInterviewed,toTested,toSelected,toOffered,toInterviewCalled,toTestCalled,toFinalInterviewCalled,toFinalInterviewed,toJoined) {
		
       //alert(opencv);
       
        $("#chart").kendoChart({
            
                title: {
                    position: "top",
                    text: "RCA Summary - From "+from+" To "+to,
                    font: "18px Arial,Helvetica,sans-serif",
                     
                },
                legend: {
                    position: "right",
                    visible: true,
                    padding: 10,
                    margin: -15,
                    labels: {
                         font: "16px"
                     }
                },
                chartArea: {
                    background: ""
                },
                seriesDefaults: {
                    labels: {
                        visible: true,
                        background: "transparent",
                        template: "#= value#%",
                        font: "12px",
                         position: "outsideEnd",
                    }
                },
                series: [{
                    type: "pie",
                    startAngle: 150,
                    data: [{
                        category: "Open CV - ("+toopencv+"/"+total+")",
                        //category2: "Open CV ",
                        value: opencv,
                        color: "#9de219"
                    },{
                        category: "Rejected - ("+torejected+"/"+total+")",
                        value: rejected,
                        color: "#f55237"
                    },{
                        category: "Short Listed - ("+toshortlist+"/"+total+")",
                        value:shortlist,
                        color: "#068c35"
                    }
                    
                    
                    ,{
                        category: "Interviewed - ("+toInterviewed+"/"+total+")",
                        value: Interviewed,
                        color: "#006634"
                    },{
                        category: "Tested - ("+toTested+"/"+total+")",
                        value: Tested,
                        color: "#41aa8d"
                    },{
                        category: "Selected - ("+toSelected+"/"+total+")",
                        value: Selected,
                        color: "#0c7272"
                    }
                     ,{
                        category: "Offered - ("+toOffered+"/"+total+")",
                        value: Offered,
                        color: "#006634"
                    },{
                        category: "Interviewed Called - ("+toInterviewCalled+"/"+total+")",
                        value: InterviewCalled,
                        color: "#004d38"
                    },{
                        category: "Test Called - ("+toTestCalled+"/"+total+")",
                        value: TestCalled,
                        color: "#033939"
                    }
                     ,{
                        category: "Final Interview Called - ("+toFinalInterviewCalled+"/"+total+")",
                        value: FinalInterviewCalled,
                        color: "#006634"
                    },{
                        category: "Final Interviewed - ("+toFinalInterviewed+"/"+total+")",
                        value: FinalInterviewed,
                        color: "#004d38"
                    },{
                        category: "Joined - ("+toJoined+"/"+total+")",
                        value: Joined,
                        color: "#17578e"
                    }
                ]
                }],
                tooltip: {
                    visible: true,
                    format: "{0}%"
                },
                seriesClick: onSeriesClick
            });
        }

        $(document).ready(createChart);
        $(document).bind("kendo:skinChange", createChart);
</script>
            <style scoped>
                label{width: 100px;display:block}
                .chart-wrapper {
                	margin: 27px 0 0 20px;
                	width: 700px;
                	height: 1400px;
                        float: left;
                        
                	background: url("../../content/shared/styles/chart-wrapper-small.png") transparent no-repeat 0 0;
                }
                
                .chart-wrapper .k-chart {
                    height: 800px;
                    padding: 0px 56%;
                    width:800px;
                    top: -43px;
                }
                .offline-button {
                    background: none repeat scroll 0 0 #8E8E8E;
                    border-radius: 16px 16px 16px 16px;
                    color: #FFFFFF;
                    display: inline-block;
                    height: 30px;
                    line-height: 30px;
                    margin: 10px 23px;
                    padding: 0 16px;
                    text-decoration: none;
                }
                .sonata-bc div.connection .control-group {
    padding: 0 20px 0 20px;
}
  .weather {
                    /*width: 160px;*/
                    padding: 15px 0 0 0;
                    /*float: right;*/
                    height: auto;
                }
            </style>
        </div>

</body>
</html>